#define _CRT_SECURE_NO_WARNINGS 1
class MyStack {
public:

    queue<int> _pushq;
    queue<int> _popq;

    MyStack() {

    }

    void push(int x) {
        _pushq.push(x);
    }

    int pop() {
        int val = top();

        if (_pushq.empty())
        {
            while (_popq.size() > 1)
            {
                _pushq.push(_popq.front());
                _popq.pop();
            }

            _popq.pop();
        }
        else
        {
            while (_pushq.size() > 1)
            {
                _popq.push(_pushq.front());
                _pushq.pop();
            }

            _pushq.pop();
        }

        return val;

    }

    int top() {
        if (_pushq.empty())
            return _popq.back();
        else
            return _pushq.back();
    }

    bool empty() {
        return _pushq.empty() && _popq.empty();
    }
};